import { createRouter,createWebHashHistory} from "vue-router"
import Layout from '@/views/layout/Layout.vue'

const routes = [
    {name: 'login',path: '/login', component: () => import('@/views/login/index.vue'),meta: {title: '登录', icon: 'home'}},
    {path: '/404', component: () => import('@/views/404.vue')},
    {
        path: '',
        component: Layout,
        redirect: '/home',
        children: [{
            path: 'home',
            name: 'home',
            component: () => import('@/views/home/index.vue'),
            meta: {title: '首页', icon: 'home'}
        }]
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

// 导航守卫
router.beforeEach((to,from,next)=>{
    console.log(to)
    if (router.hasRoute(to.name)) {
        document.title = to.meta.title
        document.icon = to.meta.icon
        next()
    }else {
        // next('/404')
    }
})

export default router

